package com.example.vocab.dao;

import com.example.vocab.entity.History;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Repository
public interface HistoryDao {

    @Select("select * from history where username=#{username} order by score desc limit 10")
    List<History> getHistory(@Param("username") String username);

    @Insert("insert into history(username,score,time) value(#{username},#{score},#{time})")
    int addHistory(@Param("username") String username,@Param("score") int score,@Param("time") String time);

    @Select("select * from history h1 where score=(select max(score) from history h2 where h1.username=h2.username) order by score desc LIMIT 10")
    List<History> getRank();
}
